package jp.ac.aiit.spg.entity;

import java.io.Serializable;
import java.util.*;
import javax.persistence.*;

@Entity
public class SpgUser implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	// vesion ***********************************
	@Version
	private Integer version;
	
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	
	
	// id ***********************************
	@Id
	@GeneratedValue
	private Integer id;
	
	public Integer getId(){
		return this.id;
	}
	
	// ユーザー名（ログインに使用） *********************************
	@Column(unique=true, nullable=false)
	private String name;
	
	public String getName(){
		return this.name;
	}
	
	public void setName(String name){
		this.name = name;
	}

	// パスワード（ログインに使用） *********************************
	@Column(nullable=false)
	private String password;

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	// ユーザーの説明（氏名など） *********************************
	@Column(nullable=false)
	private String description;

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	// メンバー（プロジェクト毎に個別なので複数）****************************
	@OneToMany(mappedBy="user", fetch = FetchType.EAGER)
	private Set<SpgMember> members = new HashSet<SpgMember>();
	
	public Set<SpgMember> getMembers(){
		return this.members;
	}

	public void setMembers(Set<SpgMember> members) {
		this.members = members;
	}
	
	public void addMember(SpgMember m) {
		// 関連の処理に責任を持つ
		this.members.add(m);
		m.setUser(this);
	}
	
	public void removeMember(SpgMember sm) {
		this.members.remove(sm);
	}

	// ToDo（１個） *********************************
	@OneToOne
	private SpgToDo todo;

	public SpgToDo getTodo() {
		return this.todo;
	}

	public void setTodo(SpgToDo todo) {
		this.todo = todo;
	}


	
}
